<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <script src="../js/jsonAjax.js"></script>
    <link rel="stylesheet" href="../css/myequipment.css">
    <script src="../js/jquery.min.js"></script>    <script src="../js/fontzize.js"></script>
    <script src="../js/vue.min.js"></script>
    <script src="../js/choice.js"></script>
    <link href="../css/choice.min.css" rel="stylesheet" type="text/css"/>
    <link href="../css/telregister.css" rel="stylesheet" type="text/css"/>

</head>
<body>
<div id="app">
    <div class="centheader">
        <div class="active">手机号</div>
        <div @click="emlregister">邮箱</div>
    </div>
    <section>
        <div class="logo"><img src="../imgs/logo.png"/>
        </div>
        <dl>
            <dd class="cent"> <input id="changCity" v-model="countryCode" class="changinput" ></dd>
        </dl>
        <dl>
            <dd class="cent"><input type="tel" onkeyup="value=value.replace(/[^\d]/g,'') " ng-pattern="/[^a-zA-Z]/" placeholder="请输入手机" v-model="username"></dd>
        </dl>
        <dl>
            <dt><input type="text" placeholder="请验证码" v-model="Code"></dt>
            <dd class="lef"><input @click="authentication" type="button" v-model="Counttex"  :disabled="disabledSty" :class="{disabled:!disabledSty}"></dd>
        </dl>
        <dl>
            <dd class="cent"><input type="password" placeholder="请输6-20位密码" v-model="password" onkeyup="value=value.replace(/[, ]/g,'') " ></dd>
        </dl>
        <input class="signin" type="button" @click="Submit" value=" 绑定" :disabled="disableSubmit" :class="{signinup:!disableSubmit}">
    </section>
    <div class="popuparticle" v-html="tishi" v-if="tishidisa"></div>
</div>
<script>
    //手机注册
    Vue.config.debug = true;
    app = new Vue({
        el: "#app",
        data: {
            changCity: [
                {
                    "country": "阿尔巴尼亚",
                    "code": "355"
                },
                {
                    "country": "阿尔及利亚",
                    "code": "213"
                },
                {
                    "country": "安道尔",
                    "code": "33628"
                },
                {
                    "country": "安哥拉",
                    "code": "224"
                },
                {
                    "country": "阿根廷",
                    "code": "54"
                },
                {
                    "country": "澳大利亚",
                    "code": "61"
                },
                {
                    "country": "奥地利",
                    "code": "43"
                },
                {
                    "country": "巴哈马",
                    "code": "1809"
                },
                {
                    "country": "巴林",
                    "code": "973"
                },
                {
                    "country": "孟加拉国",
                    "code": "880"
                },
                {
                    "country": "巴巴多斯",
                    "code": "1809"
                },
                {
                    "country": "巴西",
                    "code": "55"
                },
                {
                    "country": "比利时",
                    "code": "32"
                },
                {
                    "country": "伯利兹",
                    "code": "501"
                },
                {
                    "country": "贝宁",
                    "code": "229"
                },
                {
                    "country": "百幕大",
                    "code": "1809"
                },
                {
                    "country": "不丹",
                    "code": "975"
                },
                {
                    "country": "波利维亚",
                    "code": "591"
                },
                {
                    "country": "博茨瓦纳",
                    "code": "267"
                },
                {
                    "country": "文莱",
                    "code": "673"
                },
                {
                    "country": "保加利亚",
                    "code": "359"
                },
                {
                    "country": "缅甸",
                    "code": "95"
                },
                {
                    "country": "布隆迪",
                    "code": "257"
                },
                {
                    "country": "喀麦隆",
                    "code": "237"
                },
                {
                    "country": "加拿大",
                    "code": "1"
                },
                {
                    "country": "加那利群岛",
                    "code": "34"
                },
                {
                    "country": "佛得角",
                    "code": "238"
                },
                {
                    "country": "开曼群岛",
                    "code": "1809"
                },
                {
                    "country": "中非共和国",
                    "code": "236"
                },
                {
                    "country": "乍得",
                    "code": "235"
                },
                {
                    "country": "智利",
                    "code": "56"
                },
                {
                    "country": "中国",
                    "code": "86"
                },
                {
                    "country": "哥伦比亚",
                    "code": "57"
                },
                {
                    "country": "刚果",
                    "code": "242"
                },
                {
                    "country": "哥斯达黎加",
                    "code": "506"
                },
                {
                    "country": "古巴",
                    "code": "53"
                },
                {
                    "country": "塞浦路斯",
                    "code": "357"
                },
                {
                    "country": "捷克斯洛伐克",
                    "code": "42"
                },
                {
                    "country": "丹麦",
                    "code": "45"
                },
                {
                    "country": "吉布提",
                    "code": "253"
                },
                {
                    "country": "多米尼加国",
                    "code": "1809"
                },
                {
                    "country": "东萨摩亚",
                    "code": "685"
                },
                {
                    "country": "厄瓜多尔",
                    "code": "593"
                },
                {
                    "country": "埃及",
                    "code": "20"
                },
                {
                    "country": "萨尔瓦多",
                    "code": "503"
                },
                {
                    "country": "英国",
                    "code": "44"
                },
                {
                    "country": "赤道几内亚",
                    "code": "240"
                },
                {
                    "country": "埃塞俄比亚",
                    "code": "251"
                },
                {
                    "country": "福克兰群岛",
                    "code": "306"
                },
                {
                    "country": "斐济",
                    "code": "679"
                },
                {
                    "country": "芬兰",
                    "code": "358"
                },
                {
                    "country": "法国",
                    "code": "33"
                },
                {
                    "country": "法属波里尼西亚",
                    "code": "689"
                },
                {
                    "country": "加蓬",
                    "code": "241"
                },
                {
                    "country": "冈比亚",
                    "code": "220"
                },
                {
                    "country": "德国",
                    "code": "49"
                },
                {
                    "country": "加纳",
                    "code": "233"
                },
                {
                    "country": "希腊",
                    "code": "30"
                },
                {
                    "country": "格林纳达",
                    "code": "1809"
                },
                {
                    "country": "关岛",
                    "code": "671"
                },
                {
                    "country": "圭亚那",
                    "code": "592"
                },
                {
                    "country": "海地",
                    "code": "509"
                },
                {
                    "country": "洪都拉斯",
                    "code": "504"
                },
                {
                    "country": "香港",
                    "code": "852"
                },
                {
                    "country": "匈牙利",
                    "code": "36"
                },
                {
                    "country": "冰岛",
                    "code": "354"
                },
                {
                    "country": "印度",
                    "code": "91"
                },
                {
                    "country": "印度尼西亚",
                    "code": "62"
                },
                {
                    "country": "伊朗",
                    "code": "98"
                },
                {
                    "country": "伊拉克",
                    "code": "964"
                },
                {
                    "country": "爱尔兰",
                    "code": "353"
                },
                {
                    "country": "以色列",
                    "code": "972"
                },
                {
                    "country": "意大利",
                    "code": "39"
                },
                {
                    "country": "牙买加",
                    "code": "1809"
                },
                {
                    "country": "日本",
                    "code": "81"
                },
                {
                    "country": "约旦",
                    "code": "962"
                },
                {
                    "country": "几内亚",
                    "code": "224"
                },
                {
                    "country": "柬埔寨",
                    "code": "855"
                },
                {
                    "country": "肯尼亚",
                    "code": "254"
                },
                {
                    "country": "朝鲜民主主义人民共和国",
                    "code": "850"
                },
                {
                    "country": "韩国",
                    "code": "82"
                },
                {
                    "country": "科威特",
                    "code": "965"
                },
                {
                    "country": "老挝",
                    "code": "856"
                },
                {
                    "country": "黎巴嫩",
                    "code": "961"
                },
                {
                    "country": "莱索托",
                    "code": "266"
                },
                {
                    "country": "利比里亚",
                    "code": "231"
                },
                {
                    "country": "利比亚",
                    "code": "218"
                },
                {
                    "country": "列支敦士登",
                    "code": "41"
                },
                {
                    "country": "卢森堡",
                    "code": "352"
                },
                {
                    "country": "马达加斯加",
                    "code": "261"
                },
                {
                    "country": "马拉维",
                    "code": "265"
                },
                {
                    "country": "马来西亚",
                    "code": "60"
                },
                {
                    "country": "马尔代夫",
                    "code": "960"
                },
                {
                    "country": "马里",
                    "code": "223"
                },
                {
                    "country": "马耳他",
                    "code": "356"
                },
                {
                    "country": "马里亚纳群岛",
                    "code": "670"
                },
                {
                    "country": "马提尼克(法)",
                    "code": "596"
                },
                {
                    "country": "毛里塔尼亚",
                    "code": "222"
                },
                {
                    "country": "毛里求斯",
                    "code": "230"
                },
                {
                    "country": "墨西哥",
                    "code": "52"
                },
                {
                    "country": "摩纳哥",
                    "code": "3393"
                },
                {
                    "country": "蒙特塞拉特岛(英)",
                    "code": "1809"
                },
                {
                    "country": "摩洛哥",
                    "code": "212"
                },
                {
                    "country": "莫桑比克",
                    "code": "258"
                },
                {
                    "country": "纳米比亚",
                    "code": "264"
                },
                {
                    "country": "瑙鲁",
                    "code": "674"
                },
                {
                    "country": "尼伯尔",
                    "code": "977"
                },
                {
                    "country": "新喀里多尼亚",
                    "code": "687"
                },
                {
                    "country": "新西兰",
                    "code": "64"
                },
                {
                    "country": "尼加拉瓜",
                    "code": "505"
                },
                {
                    "country": "尼日尔",
                    "code": "227"
                },
                {
                    "country": "尼日利亚",
                    "code": "234"
                },
                {
                    "country": "纽埃岛",
                    "code": "683"
                },
                {
                    "country": "诺福克岛",
                    "code": "6723"
                },
                {
                    "country": "挪威",
                    "code": "47"
                },
                {
                    "country": "荷兰",
                    "code": "31"
                },
                {
                    "country": "阿曼",
                    "code": "968"
                },
                {
                    "country": "巴基斯坦",
                    "code": "92"
                },
                {
                    "country": "巴拿马",
                    "code": "507"
                },
                {
                    "country": "巴布亚新几内亚",
                    "code": "675"
                },
                {
                    "country": "巴拉圭",
                    "code": "595"
                },
                {
                    "country": "秘鲁",
                    "code": "51"
                },
                {
                    "country": "波多黎各",
                    "code": "1809"
                },
                {
                    "country": "菲律宾",
                    "code": "63"
                },
                {
                    "country": "波兰",
                    "code": "48"
                },
                {
                    "country": "葡萄牙",
                    "code": "351"
                },
                {
                    "country": "卡塔尔",
                    "code": "974"
                },
                {
                    "country": "留尼旺岛(法)",
                    "code": "262"
                },
                {
                    "country": "罗马尼亚",
                    "code": "40"
                },
                {
                    "country": "卢旺达",
                    "code": "250"
                },
                {
                    "country": "圣马力诺",
                    "code": "39549"
                },
                {
                    "country": "圣多美及普林西比",
                    "code": "239"
                },
                {
                    "country": "沙特阿拉伯",
                    "code": "966"
                },
                {
                    "country": "塞内加尔",
                    "code": "221"
                },
                {
                    "country": "塞舌尔",
                    "code": "248"
                },
                {
                    "country": "塞拉利昂",
                    "code": "232"
                },
                {
                    "country": "新加坡",
                    "code": "65"
                },
                {
                    "country": "所罗门群岛",
                    "code": "677"
                },
                {
                    "country": "索马里",
                    "code": "252"
                },
                {
                    "country": "南非",
                    "code": "27"
                },
                {
                    "country": "西班牙",
                    "code": "34"
                },
                {
                    "country": "斯里兰卡",
                    "code": "94"
                },
                {
                    "country": "圣克里斯托弗和尼维斯",
                    "code": "1809"
                },
                {
                    "country": "圣卢西亚",
                    "code": "1809"
                },
                {
                    "country": "圣文森特岛",
                    "code": "1809"
                },
                {
                    "country": "苏丹",
                    "code": "249"
                },
                {
                    "country": "苏里南",
                    "code": "597"
                },
                {
                    "country": "斯威士兰",
                    "code": "268"
                },
                {
                    "country": "瑞典",
                    "code": "46"
                },
                {
                    "country": "瑞士",
                    "code": "41"
                },
                {
                    "country": "叙利亚",
                    "code": "963"
                },
                {
                    "country": "台湾",
                    "code": "886"
                },
                {
                    "country": "坦桑尼亚",
                    "code": "255"
                },
                {
                    "country": "泰国",
                    "code": "66"
                },
                {
                    "country": "多哥",
                    "code": "228"
                },
                {
                    "country": "汤加",
                    "code": "676"
                },
                {
                    "country": "特立尼达和多巴哥",
                    "code": "1809"
                },
                {
                    "country": "突尼斯",
                    "code": "216"
                },
                {
                    "country": "土耳其",
                    "code": "90"
                },
                {
                    "country": "特克斯和凯科斯群岛(英)",
                    "code": "1809"
                },
                {
                    "country": "科摩罗",
                    "code": "269"
                },
                {
                    "country": "科克群岛(新)",
                    "code": "682"
                },
                {
                    "country": "阿拉伯联合酋长国",
                    "code": "971"
                },
                {
                    "country": "乌干达",
                    "code": "256"
                },
                {
                    "country": "美国",
                    "code": "1"
                },
                {
                    "country": "乌拉圭",
                    "code": "598"
                },
                {
                    "country": "委内瑞拉",
                    "code": "58"
                },
                {
                    "country": "越南",
                    "code": "84"
                },
                {
                    "country": "也门",
                    "code": "969"
                },
                {
                    "country": "南斯拉夫",
                    "code": "38"
                },
                {
                    "country": "扎伊尔",
                    "code": "243"
                },
                {
                    "country": "赞比亚",
                    "code": "260"
                },
                {
                    "country": "津巴布韦",
                    "code": "263"
                }],
            countryCode: '86',
            Code:'',
            username: '',
            password: '',
            type:0,
            Counttex:'获取验证码',
            disabledSty:true,
            tishidisa:false,
            tijiao:false,
            tishi:""
        },
        mounted:function () {
            var _this = this;
            setTimeout(function(){
                getStages('weixin');
            },60);
            setTimeout(function(){
                console.log( StagesDatas);
                _this.weixindata=StagesDatas;
            },180);
        },
        watch: {
                username: function (val, oldVal) {
                    if(this.countryCode=="86"){
                        var tel=/^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|18[0-9]{9}$/;
                        console.log(this.countryCode);
                        if (tel.test(val)) {
                            this.disabledSty=false;
                            this.tijiao=true;
                        }else {
                            this.disabledSty=true;
                            this.tijiao=false;
                        }
                    }else if(val.length>4) {
                        this.disabledSty=false;
                        this.tijiao=true;
                    }
                    else {
                        this.disabledSty=true;
                        this.tijiao=false;
                    }
            }
        },
        computed:{
            disableSubmit:function () {
                if(this.tijiao==true&&this.Code.length>0&&this.password.length>5&&this.password.length<20){
                    return false;
                }else {
                    return true;
                }
            }

        },
        methods: {
            authentication:function () {
                var _this=this;
                _this.disabledSty=true;
                this.Count=60;
                _this.Counttex="重发("+_this.Count+")";
                var settime=setInterval(function() {
                    _this.Count--;
                    _this.Counttex="重发("+_this.Count+")";
                    if(_this.Count<1){
                        _this.disabledSty=false;
                        _this.Counttex="重发";
                        clearInterval(settime);
                    }
                }, 1000);
                //02 发送验证码√
                jsonAjax("/Home/User/sendsafecode",
                    {
                        country_code:_this.countryCode,
                        type:3,
                        username: _this.username,
                        usertype:1
                    }
                ).done(function (data) {
                    console.log(data)
                    if(data.msg == "手机号被占用"){
                        _this.tishidisa=true;
                        _this.tishi="手机号被占用";
                        setTimeout(function () {
                            _this.tishidisa=false;
                        },3000);
                        _this.disabledSty=false;
                        _this.Counttex="获取验证码";
                        clearInterval(settime);
                    }else {
                        _this.tishidisa=true;
                        _this.tishi="验证码已发送";
                        setTimeout(function () {
                            _this.tishidisa=false;
                        },3000);
                    }
                })
                    .fail(function () {
                        console.log("error");
                    });

            },
            Submit: function () {
                var _this = this;
                //接口名称 23 微信授权信息注册并绑定本站用户
                jsonAjax("/Home/User/wx_register_bind",
                    {
                        city: _this.weixindata.usermsg.city,
                        country: _this.weixindata.usermsg.country,
                        country_code: _this.countryCode,
                        headimgurl: _this.weixindata.usermsg.headimgurl,
                        nickname: _this.weixindata.usermsg.nickname,
                        openid: _this.weixindata.usermsg.openid,
                        password: _this.password,
                        province: _this.weixindata.usermsg.province,
                        repassword: _this.password,
                        safecode: _this.Code,
                        sex: _this.weixindata.usermsg.sex,
                        type: 3,
                        unionid: _this.weixindata.usermsg.unionid,
                        username: _this.username
                    }
                ).done(function (data) {

                    if (data.code ==0) {
                        console.log(data);
                        var usermsg=[{
                            keyname:"user",
                            usermsg:data.data,
                            languages:'zh-cn'
                        }];
                        setstages(usermsg);
                        _this.asynchronous(data.data.access_token,data.data.uid)
                    }
                    else {
                        _this.tishidisa=true;
                        _this.tishi=data.msg;
                        setTimeout(function () {
                            _this.tishidisa=false;
                        },3000);
                    }
                })
                    .fail(function () {
                        console.log("error");
                    });
            },
            asynchronous: function (token, uid) {
                var _this = this;
                //11 根据用户ID获取设备列表√
                jsonAjax("/Home/Device/get_device_list_by_uid/Home/User/api_login",
                    {
                        access_token: token,
                        uid: uid
                    }
                ).done(function (data) {
                    if (data.msg == "获取数据失败") {
                        if (data.data.length == 0) {
                           window.location.href = golinks("associateddevice/wifinetwork.html");
                        } else {

                        }
                    } else if (data.code ==0) {
                        var device_id =[{
                            keyname: "device_ids",
                            usermsg: data.data
                        },{
                            keyname: "device_id",
                            usermsg: data.data[0].device_id
                        }
                        ];
                        setstages(device_id);
                        window.location.href = golinks("medicationplan.html");
                    }
                    console.log(data);
                })
                    .fail(function () {
                        console.log("error");
                    });

            },
            emlregister:function () {
                window.location.href=golinks('lodings/emlregister.html')
            },

        }

    });

    var datacity = [];
    $('#changCity').choice().scroller({
        theme: 'ios',
        display: 'bottom',
        lang: 'zh',
        onInit: function (event, inst) {
            for (var i = 0; i < app.changCity.length; i++) {
                datacity.push('-' + app.changCity[i].code + '-' + app.changCity[i].country)
            }
        },
        wheels: [
            [{
                data: datacity
            }]
        ],
        onSet: function (event, inst) {
            app.countryCode = inst._value.replace(/[^0-9]/ig, "");
            app.username='';

        }
    });

</script>
</body>
</html>